package cn.kgc.fcm.dsbank.utils;

import java.util.ArrayList;
import java.util.List;

public class Pager {
	
	private int pageSize = 4;//显示记录数
	private int pageIndex = 1;//当前页
	private int totalRow;//总记录数
	private int totalPage;//总页数
	
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(int pageIndex) {
		if(pageIndex < 1) {
			pageIndex = 1;
		} else {
		this.pageIndex = pageIndex;
		}
	}
	public int getTotalRow() {
		return totalRow;
	}
	public void setTotalRow(int totalRow) {
		this.totalRow = totalRow;
		
		this.totalPage = totalRow % pageSize == 0 ? totalRow /pageSize : totalRow /pageSize + 1;

		if(pageIndex > totalPage){
			pageIndex = totalPage;
		}
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	
	public int getStartIndex(){

		return (pageIndex-1)*pageSize;
	}
	
	@Override
	public String toString() {
		return "Pager{" +
				"pageSize=" + pageSize +
				", pageIndex=" + pageIndex +
				", totalRow=" + totalRow +
				", totalPage=" + totalPage +
				'}';
	}
}
